/**
 * Created by leon on 2017/5/10.
 */
(function () {
    'use strict';

    angular.module('App.pages.member')
        .controller('MyInfoCtrl',MyInfoCtrl);
    function MyInfoCtrl($scope,MemberModel,LoginAccountAuth,AppUtils) {

        var vm = this;
        var objParams={};


        LoginAccountAuth.getAccount().then(function(data){
            vm.loginAccount = data;
            objParams.id = vm.loginAccount.memberId;
            MemberModel.getMemberInfo(objParams).$promise.then(function(response){
                if(response.stat == 'err') {
                    AppUtils.showAlert(response.msg);
                }else{
                    vm.memberInfo = response.memberInfo;
                }
            })
        })


        $scope.turnTo=function (){
            angular.element(".numberOne").css("display","none");
            angular.element(".numberTwo").css("display","block");
            angular.element(".numberThree").css("display","none");
        }

        $scope.turnB=function(){
            angular.element(".numberOne").css("display","none");
            angular.element(".numberTwo").css("display","none");
            angular.element(".numberThree").css("display","block");
        }



        $scope.cancel=function () {
            angular.element(".numberOne").css("display","block");
            angular.element(".numberTwo").css("display","none");
            angular.element(".numberThree").css("display","none");
        }

        $scope.updateInfo=function () {
            objParams.memberName=vm.Name;
            if(objParams.memberName==""){
                AppUtils.showAlert("您没有输入姓名,请重新输入！");
            }else {
                MemberModel.Modify(objParams).$promise.then(function(response){
                    if(response.stat == 'err') {
                        AppUtils.showAlert(response.msg);
                    }else{
                        angular.element(".numberOne").css("display","block");
                        angular.element(".numberTwo").css("display","none");
                        angular.element(".numberThree").css("display","none");
                        AppUtils.showAlert(response.msg);
                    }
                })
            }
        }


        $scope.updatePhone=function () {
            objParams.memberPhone = vm.phoneNumber;
            if(objParams.memberPhone.length!=""){
                MemberModel.Modify(objParams).$promise.then(function(response){
                    if(response.stat == 'err') {
                        AppUtils.showAlert(response.msg);
                    }else{
                        angular.element(".numberOne").css("display","block");
                        angular.element(".numberTwo").css("display","none");
                        angular.element(".numberThree").css("display","none");
                        AppUtils.showAlert(response.msg);
                    }
                })
            }else{
                AppUtils.showAlert("您没有输入手机号码，请重新输入！");
            }
        }
    }
})();